package com.neo.impatient.C08_extends.C08_12_equals

class EqualsTest(val name: String, val age: Int) {


  override def equals(obj: scala.Any): Boolean = {

    obj.isInstanceOf[EqualsTest] && {
      val that = obj.asInstanceOf[EqualsTest]
      name == that.name && age == that.age
    }
  }

  override def hashCode(): Int = (name,age).##
}


object EqualsTest{


  def main(args: Array[String]): Unit = {
    val name1 = new EqualsTest("zhao",29)
    val name2 = new EqualsTest("shun",30)
    val name3 = new EqualsTest("zhao",29)


    if(name1.equals(name2))
      println(true)
    else
      println(false)


    if(name1.equals(name3))
      println(true)
    else
      println(false)


  }
}
